using System;

namespace ICSharpCode.TextEditor.Formatting.Intellisense
{
    public class NetVersionCompletionData : DefaultCompletionData
    {
        public NetVersionCompletionData(string text, int imageIndex)
            : base(text, imageIndex)
        {
        }

        public NetVersionCompletionData(string text, string description, int imageIndex)
            : base(text, description, imageIndex)
        {
        }

        public override bool InsertAction(TextArea textArea, char ch)
        {
            string wordBeforeCaret = textArea.GetWordBeforeCaret();
            Caret caret = textArea.Caret;
            int num = caret.Offset + 1;
            int num2 = num;
            if (!string.IsNullOrEmpty(wordBeforeCaret))
            {
                num -= wordBeforeCaret.Length + 1;
                num2--;
                if (num2 - num > 0)
                {
                    textArea.Document.Remove(num, num2 - num);
                }
                textArea.Caret.Position = textArea.Document.OffsetToPosition(Math.Min(num, textArea.Document.TextLength));
            }
            string text = (base.text ?? "") ?? "";
            if (wordBeforeCaret == ".")
            {
                text = text.Substring(text.LastIndexOf("."));
            }
            textArea.InsertString(text);
            return false;
        }
    }
}
